<?

include "../model/model.php";
require "facebook_sdk/facebook.php";
function recentProduct(){
	$recent_data = get_recent_product();
	for($i=1; $i<=5; $i++){
		echo "<a href ='../view/product.html?product_name=";
		echo $recent_data[$i][2];
		echo "' target ='main'>";
		echo "<table>";
		echo "<img src='../Images/",$recent_data[$i][4],"'"," />";
		echo "<td id ='name'>",$recent_data[$i][2],"</td>";
		echo "<tr><td>",substr($recent_data[$i][3],0,50),"...","</td></tr>";
		echo "</tr>";
		echo "</table>";
		echo "</a>";
	}
}

function recommendProduct(){
	$recommend_data = get_best_product();
	for($i=1; $i<=5; $i++){
		echo "<a href ='../view/product.html?product_name=";
		echo $recommend_data[$i][3];
		echo "' target ='main'>";
		echo "<table>";
		echo "<img src='../Images/",$recommend_data[$i][5],"'"," />";
		echo "<td id ='name'>",$recommend_data[$i][3],"</td>";
		echo "<tr><td>",substr($recommend_data[$i][4],0,50),"...","</td></tr>";
		echo "</tr>";
		echo "</table>";
		echo "</a>";
	}
}


function interestProduct(){
$user = null;
$config = array(
    'appId' => '314860265232330',
    'secret' => 'de61791ac4eec6920ab83856c90b7861',
  );
	try{
		$facebook = new Facebook($config);
		$user_id = $facebook->getUser();		
		$user = $facebook->getUser();
		$user_profile = $facebook->api('/me');
		}catch (FacebookApiException $e){
		error_log($e);
		}
		
	$interest_data = getInterestProduct($user);
	if($user == null){}
	else{
		for($i=1; $i<=5; $i++){
		if($interest_data[$i][1] == null){}
		else{
			echo "<a href ='../view/product.html?product_name=";
			echo $interest_data[$i][1];
			echo "' target ='main'>";
			echo "<table>";
			echo "<img src='../Images/",$interest_data[$i][3],"'"," />";
			echo "<td id ='name'>",$interest_data[$i][1],"</td>";
			echo "<tr><td>",substr($interest_data[$i][2],0,50),"...","</td></tr>";
			echo "</tr>";
			echo "</table>";
			echo "</a>";
			}
		}
	}
	
	
}

?>